package com.big_data.main.controller;

import com.big_data.main.model.dto.AreaDataDto;
import com.big_data.main.model.dto.AreaLogDto;
import com.big_data.main.resp.RespUtil;
import com.big_data.main.resp.ResponseBean;
import com.big_data.main.service.OriginalCovid19MapWangyiLogService;
import com.big_data.main.service.OriginalCovid19MapWangyiServiceImpl;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("covid19")
@RestController
@CrossOrigin
public class Covid19Controller {

    @Resource
    OriginalCovid19MapWangyiServiceImpl originalCovid19MapWangyiService;

    @Resource
    OriginalCovid19MapWangyiLogService originalCovid19MapWangyiLogService;

    @RequestMapping("get-data-map-for-area")
    public ResponseBean getDataMapForArea(@Validated AreaDataDto areaDataDto) {
        if (!StringUtils.isEmpty(areaDataDto.getId()) && areaDataDto.getId() != 0) {
            return RespUtil.success(originalCovid19MapWangyiService.getDataMapForAreaForId(areaDataDto.getId()));
        }
        if (!StringUtils.isEmpty(areaDataDto.getAddressName())) {
            return RespUtil.success(originalCovid19MapWangyiService.getDataMapForAreaForAddressName(areaDataDto.getAddressName()));
        }
        if (!StringUtils.isEmpty(areaDataDto.getAddressNameEn())) {
            return RespUtil.success(originalCovid19MapWangyiService.getDataMapForAreaForAddressNameEn(areaDataDto.getAddressNameEn()));
        }
        return RespUtil.success(originalCovid19MapWangyiService.getDataMapForAreaForId(null));
    }

    @RequestMapping("get-map-info-for-area")
    public ResponseBean getMapInfoForArea(@Validated AreaDataDto areaDataDto) {
        return RespUtil.success(originalCovid19MapWangyiService.getMapInfoForAreaForId(areaDataDto.getId()));
    }

    @RequestMapping("get-log-data-for-area")
    public ResponseBean getLogDataForArea(@Validated AreaLogDto areaLogDto) {
        String name = areaLogDto.getAddressName() == null ? "" : areaLogDto.getAddressName();
        return RespUtil.success(originalCovid19MapWangyiLogService.getLogDataForArea(name));
    }

    @RequestMapping("get-data-map-top20-for-area")
    public ResponseBean getDataMapTop20ForArea(@Validated AreaDataDto areaDataDto) {
        if (!StringUtils.isEmpty(areaDataDto.getId()) && areaDataDto.getId() != 0) {
            return RespUtil.success(originalCovid19MapWangyiService.getMapTopForAreaId(areaDataDto.getId(), 20));
        }
        return RespUtil.success(originalCovid19MapWangyiService.getMapTopForAreaId(null, 20));
    }

    @RequestMapping("get-data-map-top20-for-area-order-by-cur")
    public ResponseBean getMapTopOrderByCurrForAreaId(@Validated AreaDataDto areaDataDto) {
        if (!StringUtils.isEmpty(areaDataDto.getId()) && areaDataDto.getId() != 0) {
            return RespUtil.success(originalCovid19MapWangyiService.getMapTopOrderByCurrForAreaId(areaDataDto.getId(), 20));
        }
        return RespUtil.success(originalCovid19MapWangyiService.getMapTopOrderByCurrForAreaId(null, 20));
    }
}
